<template>
  <div>
    <el-dialog
      title="设置分数"
      :close-on-click-modal="false"
      :lock-scroll="false"
      :visible.sync="dialogVisible"
      width="600px"
    >
      <div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="分数">
            <el-input-number
              v-model="form.score"
              :min="0"
              :max="maxScore"
              size="medium"
              label="分数"
            ></el-input-number>
            <span style="color: #999"> ( 0 - {{ maxScore }} )</span>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.readOver"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { reviewPaperExamHis,testExamHisQueryById } from "@/api/admin/exam/testExam";
export default {
  data() {
    return {
      dialogVisible: false,
      maxScore: 10,
      form: {
        score: 0,
        readOver: ''
      },
    };
  },
  props: ["examInfo"],
  mounted() {
    this.$bus.$on("writeScore", (row) => {
      // console.log(this.examInfo);
      // return
      let { testPaperAnswerVOList } = this.examInfo;
      let obj  = testPaperAnswerVOList.filter((v) => v.id == row.id)[0];
      this.form = JSON.parse(JSON.stringify(obj))
      this.maxScore = parseInt(row.score);
      this.dialogVisible = true;
    });
  },
  beforeDestroy() {
    this.$bus.$off("writeScore");
  },
  methods: {
    submitForm(form) {
      if (this.form.score == 0) {
        this.form.isRight = "N";
      } else if (this.form.score == this.maxScore) {
        this.form.isRight = "Y";
      } else {
        this.form.isRight = "P";
      }
      this.$refs[form].validate(async (valid) => {
        if (valid) {
          this.dialogVisible = false;
          await reviewPaperExamHis(this.examInfo.id, this.form);
          this.getExamHisById(this.examInfo.id);
        }
      });
    },
    async getExamHisById(id) {
      // console.log(id);
      let res = await testExamHisQueryById(id)
      let row = res.data.data[0];
      this.$bus.$emit("showExamAnswer", row, "read");
      // console.log(row);
      this.successMsg("操作成功");
    },
  },
};
</script>
<style scoped lang="scss">
</style>